﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialIn.Core.Data;
using System.Data;
using System.Text;

namespace SocialIn.Web.GiveAndTake
{
    public partial class GetHelpRequest : System.Web.UI.Page
    {
        private string userID;
        private string year;
        private string month;        

        protected void Page_Load(object sender, EventArgs e)
        {            
            userID = (Request.QueryString["u"] == null) ? string.Empty : Request.QueryString["u"].ToString();
            year = (Request.QueryString["y"] == null) ? string.Empty : Request.QueryString["y"].ToString();
            month = (Request.QueryString["m"] == null) ? string.Empty : Request.QueryString["m"].ToString();            

            ResponseHelpRequset();
        }

        private void ResponseHelpRequset()
        {
            if(User.Identity.IsAuthenticated)
            {
                SocialIn.Biz.GiveAndTake gat = new Biz.GiveAndTake();

                Result<DataTable> dt = gat.SearchHelpRequest(userID, year, month);

                StringBuilder sb = new StringBuilder();
                foreach(DataRow dr in dt.ReturnValue.Rows)
                {
                    sb.Append(string.Format("{0}/{1}/{2}/{3}/{4}/{5},", 
                        dr["Seq"].ToString(),
                        dr["NgoID"].ToString(),
                        dr["TalentID"].ToString(),
                        dr["Title"].ToString(),
                        dr["RequestDate"].ToString(),
                        dr["CodeName"].ToString()
                        ));
                }
                Response.Clear();

                if (sb.Length > 0)                                    
                    Response.Write(sb.ToString().Substring(0, sb.Length - 1));
                Response.Flush();
            }
            else
            {
                Response.Clear();                
                Response.Flush();
            }
        }       
    }
}